package com.atguigu.Func;

import com.atguigu.Util.DateFormatUtil;
import com.atguigu.bean.TrafficPageViewBean;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;

import java.lang.reflect.Field;

/**
 * @author hjy
 * @create 2023/3/15 18:34
 */
public class MyWindowFunction {
    public static <T> T getJavabeanFields(T t, TimeWindow window) throws IllegalAccessException, NoSuchFieldException {
        Class<?> aClass = t.getClass();
        //拿到stt字段
        Field stt = aClass.getDeclaredField("stt");
        stt.setAccessible(true);
        stt.set(t, DateFormatUtil.toYmdHms(window.getStart()));
        //拿到edt字段
        Field edt = aClass.getDeclaredField("edt");
        edt.setAccessible(true);
        edt.set(t,DateFormatUtil.toYmdHms(window.getEnd()));
        //拿到ts字段
        Field ts = aClass.getDeclaredField("ts");
        ts.setAccessible(true);
        ts.set(t,System.currentTimeMillis());
        return t;
    }
}
